#ifndef POLY_MODEL_H
#define POLY_MODEL_H

#include <vector>
#include "PolyMesh.h"
#include "BBox.h"
using namespace std;

namespace geom
{
	/** Class to represent polygonal 3D models, composed of several meshes*/
    class PolyModel
    {
		protected:
			/** Name of the model */
			string m_modelName;
			/** Meshes that form this model */
        	vector<PolyMesh> m_meshes;

		public:
			/** Sets the name of the model */
			void setName(string name){m_modelName = name;}
			/** Gets the name of the model */
			string name() const {return m_modelName;}
			/** Adds a mesh to the model
			  @param pm PolyMesh to add to the model */
			void addMesh(const PolyMesh & pm){ m_meshes.push_back(pm);}
			/** Gets the number of meshes currently in the model */
			int numberOfMeshes() const {return m_meshes.size();}

			/** Gets an axis-aligned bounding cube for this model */
			BBox getModelBoundingBox() const
			{
				int numMeshes = m_meshes.size();
				if(numMeshes == 0)
					return	BBox(Point3D(0,0,0),0);

				BBox result  = m_meshes[0].getMeshBoundingBox();
				for(int i=1;i<numMeshes;++i)
					result+=m_meshes[i].getMeshBoundingBox();

				return result;	
			}
			/** Gets an axis aligned bounding box (not necessarily a cube) for this model */
			FittedBBox getModelFittedBoundingBox() const
			{
				int numMeshes = m_meshes.size();
				if(numMeshes == 0)
					return	FittedBBox(Point3D(0,0,0),Point3D(0,0,0));

				FittedBBox result  = m_meshes[0].getMeshFittedBoundingBox();
				for(int i=1;i<numMeshes;++i)
					result+=m_meshes[i].getMeshFittedBoundingBox();

				return result;	
			}

			/** Gets a read-only reference to a mesh in the model
			  @param mesh Mesh number*/
			const PolyMesh& getMesh (int mesh) const {return m_meshes.at(mesh);}
			/** Gets a mesh in the model (read-write)*/
			PolyMesh& getMesh (int mesh) {return m_meshes.at(mesh);}
    };
}

#endif
